import Vue from "vue";
import VueRouter from "vue-router";
// const { isNavigationFailure, NavigationFailureType } = VueRouter;
import HomeView from "../views/HomeView.vue";
import UserView from "../views/UserView.vue";
import TransitionView from "../views/TransitionView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/about",
    name: "about",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: "/user/:id",
    component: UserView,
    meta: {
      a: "123",
    },
  },
  {
    path: "/transition",
    component: TransitionView,
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  // ...
  console.log("全局前置守卫----001", to.matched);
  next();
});

router.beforeResolve((to, from, next) => {
  // ...
  console.log("全局解析守卫----000");
  next();
});

router.afterEach((to, from) => {
  // ...
  console.log("全局后置钩子----000", to, from);
});

// router.push("/").catch((failure) => {
//   if (isNavigationFailure(failure, NavigationFailureType.aborted)) {
//     // 向用户显示一个小通知
//     alert("Error");
//   }
// });

export default router;
